//
//  AXFPayViewController.m
//  BEEQUICK
//
//  Created by HH on 16/11/23.
//  Copyright © 2016年 SevenGroup. All rights reserved.
//

#import "AXFPayViewController.h"
#import "AXFPayMentCell.h"
#import "AXFEliteCell.h"
#import "AXFFeeDetailCell.h"

static NSString *cellID = @"cellID";
static NSString * payMentCellID = @"payMentCellID";
static NSString *value1CellID = @"value1CellID";
static NSString *eliteCellID = @"eliteCellID";
static NSString *feeDetailCell = @"feeDetailCell";

@interface AXFPayViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) NSArray<NSString *> *classifyArr;
@property (nonatomic,strong) NSArray<NSDictionary *> *paymentArr;
@property (nonatomic,strong) NSArray<NSString *> *privilegeArray;
@property (nonatomic,strong) NSArray <NSString *>* stateArray;

@property (nonatomic,weak) AXFPayMentCell * payMentCell;
@end

@implementation AXFPayViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
}

- (void)setupUI
{
    UITableView *tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStyleGrouped];
    tableView.dataSource  = self;
    tableView.delegate = self;
    
    tableView.rowHeight = 45;
    
    [tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellID];
    
    [tableView registerClass:[AXFPayMentCell class] forCellReuseIdentifier:payMentCellID];
    
    [tableView registerClass:[AXFEliteCell class] forCellReuseIdentifier:eliteCellID];
    
    [tableView registerClass:[AXFFeeDetailCell class] forCellReuseIdentifier:feeDetailCell];
    
    [self.view addSubview:tableView];
    
    
    self.classifyArr = @[@"选择支付方式",@"账户信息",@"精选商品",@"费用明细"];
    
    self.paymentArr = @[@{@"name":@"支付宝支付",@"img":@"v2_zfb"},
                        @{@"name":@"微信支付",@"img":@"v2_about_wechat_logo"},
                        @{@"name":@"QQ钱包",@"img":@"icon_qq"},
                        @{@"name":@"Apple Pay",@"img":@"Apple_Pay"},
                        @{@"name":@"货到付款",@"img":@"v2_dao"}
                        ];
    self.privilegeArray = @[@"优惠券",@"积分券",@"账户余额"];
    self.stateArray = @[@"暂无可用优惠券",@"暂无可用积分券",@"暂无可用余额"];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 6;
    }
    
    if (section == 1) {
        return 4;
    }
    
    if (section == 3) {
        return 2;
    }
    
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.row == 0) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
        cell.textLabel.text = self.classifyArr[indexPath.section];
        cell.textLabel.font = [UIFont systemFontOfSize:12];
        [cell.textLabel setTextColor:[UIColor cz_colorWithHex:0x999999]];
        tableView.rowHeight = 45;
        
        
        return cell;
    }
    
    
    if (indexPath.section == 0) {
        
        AXFPayMentCell *cell = [tableView dequeueReusableCellWithIdentifier:payMentCellID forIndexPath:indexPath];
        //NSLog(@"%zd",indexPath.row);
        cell.model = self.paymentArr[indexPath.row - 1];
        tableView.rowHeight = 45;
        
        self.payMentCell = cell;
        return cell;
    }
    
    if (indexPath.section == 1) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:value1CellID];
        
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:value1CellID];
        }
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.text = self.privilegeArray[indexPath.row - 1];
        cell.detailTextLabel.text = self.stateArray[indexPath.row -1];
        
        return cell;
    }
    
    if (indexPath.section == 2) {
        
        AXFEliteCell *cell = [tableView dequeueReusableCellWithIdentifier:eliteCellID forIndexPath:indexPath];
        
        if (indexPath.row == 2) {
            
            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:value1CellID];
            if (cell == nil) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:value1CellID];
            }
            
            cell.detailTextLabel.text = @"合计:¥9";
            cell.detailTextLabel.textColor = [UIColor redColor];
        }
        
        return cell;
    }
    AXFFeeDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:feeDetailCell forIndexPath:indexPath];
    tableView.rowHeight = 120;
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0 && indexPath.row != 0 ) {
        
        self.payMentCell.index = NO;
        
        AXFPayMentCell *cell = (AXFPayMentCell *)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:indexPath.row inSection:0]];
        self.payMentCell  = cell;
        
        cell.index = !cell.index;
        
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 4;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
